package com.kk.quyan.controller;

import com.kk.quyan.common.R;
import com.kk.quyan.entity.Label;
import com.kk.quyan.entity.VO.LabelVO;
import com.kk.quyan.service.LabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: Kk
 * @create: 2020-11-22 10:29
 **/
@Api(value = "LabelController" ,description = "标签测试接口")
@RestController
@RequestMapping("label")
public class LabelController {

    @Autowired
    private LabelService labelService;

    @ApiOperation(value = "获取标签树")
    @GetMapping("getLabelTree/{labelId}")
    public R getLabelTree(@PathVariable("labelId")int labelId){
        LabelVO labelVO = labelService.buildLabelByLabelId(labelId);
        return R.ok().data("tree",labelVO);
    }

    @ApiOperation(value = "添加标签")
    @PostMapping("addLabel")
    public R addLabel(@RequestBody Label label){
        boolean flag = labelService.save(label);
        return flag?R.ok():R.error();
    }

    @ApiOperation(value = "删除标签")
    @PostMapping("deleteLabel")
    public R deleteLabel(Integer lId){
        boolean flag = labelService.removeById(lId);
        return flag?R.ok():R.error();
    }
}
